import { HashRouter, Route, Routes } from "react-router-dom"
import MyLayout from "./views/layout"
import Login from "./views/login"
import Dashboard from "./views/dashboard"
import User from "./views/user"
import Good from "./views/good/goodList"
import asyncRoutes from "./views/router"

//动态生成路由
function createMenu(asyncRoutes) {
  let result = []
  asyncRoutes.forEach(element => {
    if (element.path && element.element) {
      result.push(<Route key={element.key} path={element.path} element={element.element} />)
    }
    if (element.children) {
      element.children.forEach(element => {
        result.push(<Route key={element.key} path={element.path} element={element.element} />)
      })
    }
  })
  return result
}
export default () => {
  return (
    <HashRouter>
      <Routes>
        <Route path="/" element={<MyLayout />}>
          {createMenu(asyncRoutes)}
          {/* <Route path="/dashboard" element={<Dashboard />}></Route>
          <Route path="/user" element={<User />}></Route>
          <Route path="/good" element={<Good />}></Route> */}
        </Route>
        <Route path="/login" element={<Login />} />
      </Routes>
    </HashRouter>
  )
}
